package com.tancire.question.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.question.domain.TrainActivityProblem;
import com.tancire.question.service.ITrainActivityProblemService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 活动题目Controller
 *
 * @author tancire
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/question/trainActivityProblem")
public class TrainActivityProblemController extends BaseController {
    @Resource
    private ITrainActivityProblemService trainActivityProblemService;

    /**
     * 查询活动题目列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainActivityProblem trainActivityProblem) {
        startPage();
        List<TrainActivityProblem> list = trainActivityProblemService.selectTrainActivityProblemList(trainActivityProblem);
        return getDataTable(list);
    }

    /**
     * 导出活动题目列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:export')")
    @Log(title = "活动题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainActivityProblem trainActivityProblem) {
        List<TrainActivityProblem> list = trainActivityProblemService.selectTrainActivityProblemList(trainActivityProblem);
        ExcelUtil<TrainActivityProblem> util = new ExcelUtil<TrainActivityProblem>(TrainActivityProblem.class);
        util.exportExcel(response, list, "活动题目数据");
    }

    /**
     * 获取活动题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(trainActivityProblemService.selectTrainActivityProblemById(id));
    }

    /**
     * 新增活动题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:add')")
    @Log(title = "活动题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainActivityProblem trainActivityProblem) {
        return toAjax(trainActivityProblemService.insertTrainActivityProblem(trainActivityProblem));
    }

    /**
     * 新增活动题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:add')")
    @Log(title = "活动题目", businessType = BusinessType.INSERT)
    @PostMapping("/batch/add")
    public AjaxResult addList(@RequestBody List<TrainActivityProblem> problemList) {
        trainActivityProblemService.insertTrainActivityProblemBatch(problemList);
        return AjaxResult.success("批量保存成功");
    }

    /**
     * 修改活动题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:edit')")
    @Log(title = "活动题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainActivityProblem trainActivityProblem) {
        return toAjax(trainActivityProblemService.updateTrainActivityProblem(trainActivityProblem));
    }

    /**
     * 删除活动题目
     */
    @PreAuthorize("@ss.hasPermi('question:trainActivityProblem:remove')")
    @Log(title = "活动题目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainActivityProblemService.deleteTrainActivityProblemByIds(ids));
    }
}
